﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using DataStore.Domain;
using Infrastructure.ViewModels;

namespace UI.Controls.Dictionaries
{
    /// <summary>
    /// Interaction logic for PublisherDetailed.xaml
    /// </summary>
    public partial class PublisherDetailed : UserControl, IDictionaryItem<CompanyViewModel>
    {
        CompanyViewModel _company;
        /// <summary>
        /// Gets or sets the dictionary item.
        /// </summary>
        /// <value>The item.</value>
        public CompanyViewModel Item { 
            get
            {
                
                return _company;
            }
            set
            {
                _company = value;
                DataContext = value;
            }
        }


        /// <summary>
        /// Gets the save command for the dictionary item.
        /// </summary>
        /// <value>The save.</value>
        public ICommand Save
        {
            get
            {
                return Item.SaveCommand;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PublisherDetailed"/> class.
        /// </summary>
        public PublisherDetailed()
        {
            InitializeComponent();

            Item = new CompanyViewModel(new Company());
        }

        /// <summary>
        /// Handles the Loaded event of the UserControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (DataContext == null)
            {
                DataContext = Item;
            }
        }
    }
}